//
//  ViewController.m
//  Image圆角优化
//
//  Created by 宜必鑫科技 on 2017/11/15.
//  Copyright © 2017年 宜必鑫科技. All rights reserved.
//

#import "ViewController.h"
#import "TableViewCell.h"
#import "YYKitViewController.h"
#import "MusicController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *listTableView;
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *str = @"[]<>hahah & \" ← ←哈哈 i ¢ ¢ ¤";
    
    ///> YYCode 编码
    NSString *EscapingHTML = [str stringByEscapingHTML];
    ///> 解码
    NSString *result = [self htmlEntityDecode:EscapingHTML];
    ///> 解码
    NSString *result1 = [self HTML:EscapingHTML];
    
    NSLog(@"编码后的输入内容： %@  ",EscapingHTML);
    NSLog(@"解码后的输入内容： %@  ",result);
    NSLog(@"解码后的输入内容： %@  ",result1);
    
    CGFloat floats = [str widthForFont:[UIFont systemFontOfSize:30]];
    NSLog(@"需要的字体宽度： %f",floats);
 
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 300, 100)];
    lable.text = [self HTML:EscapingHTML];
    [self.view addSubview:lable];
    
    ///> 此时此刻的NSDate
    NSDate *senddate=[NSDate date];
    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    NSInteger interval = [zone secondsFromGMTForDate: senddate];
    NSDate *localDate = [senddate dateByAddingTimeInterval: interval];
    ///> 周日是
    NSLog(@"现在的年份：%tu  现在的星期：%tu",[localDate year],[localDate weekday]);
  
    self.listTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 100, kScreenW, kScreenH - 100) style:UITableViewStylePlain];
    self.listTableView.delegate = self;
    self.listTableView.dataSource = self;
    [self.listTableView registerClass:[TableViewCell class] forCellReuseIdentifier:@"listTableViewCell"];
    [self.listTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"TableViewCell"];
    [self.view addSubview:self.listTableView];
}

///>  解码
- (NSString *)HTML:(NSString *)html
{
    NSScanner *theScaner = [NSScanner scannerWithString:html];
    
    NSDictionary *dict = @{@"&amp;":@"&", @"&lt;":@"<", @"&gt;":@">", @"&nbsp;":@"", @"&quot;":@"\"", @"width":@"wid"};
    
    while ([theScaner isAtEnd] == NO) {
        
        for (int i = 0; i <[dict allKeys].count; i ++) {
            
            [theScaner scanUpToString:[dict allKeys][i] intoString:NULL];
            
            html = [html stringByReplacingOccurrencesOfString:[dict allKeys][i] withString:[dict allValues][i]];
        }
    }
    return html;
}

///>  解码
-(NSString *)htmlEntityDecode:(NSString *)string
{
    string = [string stringByReplacingOccurrencesOfString:@"&quot;" withString:@"\""];
    string = [string stringByReplacingOccurrencesOfString:@"&apos;" withString:@"'"];
    string = [string stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
    string = [string stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
    string = [string stringByReplacingOccurrencesOfString:@"&amp;" withString:@"&"];
    return string;
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10000;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0 || indexPath.row == 1){
        UITableViewCell *cell =  [tableView dequeueReusableCellWithIdentifier:@"TableViewCell"];
        if (indexPath.row == 0) {
            cell.textLabel.text = @"图片美白效果";
        }else{
            cell.textLabel.text = @"语音识别";
        }
        return cell;
    }
    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"listTableViewCell"];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     if (indexPath.row == 0)
     {
         UINavigationController *navc = [[UINavigationController alloc]initWithRootViewController:[YYKitViewController new]];
         [self presentViewController:navc animated:YES completion:nil];
     }
     else if(indexPath.row == 1)
     {
         UINavigationController *navc = [[UINavigationController alloc]initWithRootViewController:[MusicController new]];
         [self presentViewController:navc animated:YES completion:nil];
     }

}
@end
